﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using CastleDefender.ConfigFolder;
using Microsoft.Xna.Framework.Graphics;

namespace CastleDefender.Platform.GameScene
{
    public partial class GameWaiting : GameScene
    {
        #region VARIABLE

        protected TimeSpan tsElapsedTimeWait;
        protected SpriteFont sfFont;
        protected int intTimeWait;
        protected bool blnComplete;
    
        #endregion

        #region CONSTRUCTOR

        public GameWaiting(Game myGame)
            : base(myGame, Config.FolderBackgrounds + "Waiting")
        {
            tsElapsedTimeWait = TimeSpan.Zero;
            intTimeWait = Config.TimeWaiting;
            blnComplete = false;
            sfFont = myGame.Content.Load<SpriteFont>(Config.FolderFonts + "FontWaiting");
        }

        #endregion

        #region PUBLIC METHOD

        public override void Show()
        {
            blnComplete = false;
            base.Show();
        }

        public override void Hide()
        {
            base.Hide();
        }

        public override void Update(GameTime gameTime)
        {
            if (!blnComplete && Enabled && Visible)
            {
                tsElapsedTimeWait += gameTime.ElapsedGameTime;
                if (tsElapsedTimeWait >= TimeSpan.FromSeconds(intTimeWait))
                {
                    tsElapsedTimeWait = TimeSpan.Zero;
                    blnComplete = true;
                }
            }
            
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            if (Enabled && Visible && !blnComplete)
            {
                string wait = "Waiting...";
                string time = (Config.TimeWaiting - tsElapsedTimeWait.Seconds).ToString();

                //Độ dài của chuỗi 
                Vector2 measureWait = sfFont.MeasureString(wait);
                Vector2 measureTime = sfFont.MeasureString(time);

                //Tọa độ của chuỗi
                Vector2 posWait = (Config.ScreenSize - measureWait) / 2;
                Vector2 posTime = new Vector2(posWait.X + (measureWait.X - measureTime.X) / 2 - 5, posWait.Y + measureWait.Y - 5);

                sprBatch.DrawString(sfFont, wait, posWait, Color.White);
                sprBatch.DrawString(sfFont, time, posTime, Color.White);
            }
        }

        #endregion

        #region PUBLIC PROPERTIES

        //Trả giá trị blnComplete
        public bool Complete
        {
            get { return blnComplete; }
            private set { }
        }

        #endregion

    }
}
